﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;
using System.IO.IsolatedStorage;
using System.IO;
using Common.Library;


namespace ActivityTracker.Library
{
    public class Background
    {
        IsolatedStorageFile myIsolatedStorage1 = IsolatedStorageFile.GetUserStoreForApplication();

        public ImageBrush LoadBackground()
        {
            ImageBrush PanoramBrush = new ImageBrush();
            try
            {

                string Background = SettingsHelper.getStringValue("backGroundName");

                if (Background == "user")
                {
                    if (myIsolatedStorage1.FileExists("myImage1.jpg"))
                    {
                        BitmapImage bi = new BitmapImage();

                        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
                        {
                            using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("myImage1.jpg", FileMode.Open, FileAccess.Read))
                            {

                                bi.SetSource(fileStream);

                                PanoramBrush.ImageSource = bi;
                            }
                        }
                    }
                }
                else
                {

                    if (Background != "50.png" && Background != "")
                        PanoramBrush.ImageSource = new BitmapImage(new Uri("/Images/panoramaimages/" + Background, UriKind.Relative));
                    else
                        PanoramBrush.ImageSource = new BitmapImage(new Uri("/Images/panoramaimages/Background.jpg", UriKind.Relative));


                }
            }
            catch (Exception ex)
            {
                Exception exNew = new Exception("Exception in LoadBackground Method In ActivityTracker.Library.Themes.Background file\n\n" + ex.Message + " \n\n Stack Trace \n" + ex.StackTrace);
                throw exNew;
            }
            return PanoramBrush;
        }


    }
}
